<template>
  <div>
    <h3>{{newsinfo.title}}</h3>
    <p>
      <span>{{newsinfo.add_time}}</span>
      <span>{{newsinfo.click}}</span>
    </p>
    <div class="content" v-html="newsinfo.content"></div>
    <comment-box :id="this.id"></comment-box>
  </div>
</template> 
<script>
// 导入评论子组件

import comment from "../subcomponent/comment.vue";

export default {
  data() {
    return {
      id: this.$route.params.id,
      //将url传递的id值挂载到data上
      newsinfo: {}
    };
  },
  created() {
    this.getNewsInfo();
  },
  methods: {
    getNewsInfo() {
      this.$http.get("api/getnew/" + this.id).then(result => {
        if (result.body.status === 0) {
          //没有失败数据保存到data
          this.newsinfo = result.body.message[0];
        } else {
          Toast("获取新闻列表失败！");
        }
      });
    }
  },
  components: {
    "comment-box": comment
  }
};
</script>
<style lang="less" scoped>
</style>